package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.service.AdminUserService;
import com.cskaoyan.market.util.MybatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminUserServiceImpl implements AdminUserService {
    @Override
    public List<MarketUser> list(String page, String limit, String sort, String order, String username, String mobile) {
        SqlSession session = MybatisUtil.getSession();
        MarketUserMapper userMapper = session.getMapper(MarketUserMapper.class);
        MarketUserExample marketUserExample = new MarketUserExample();
        MarketUserExample.Criteria criteria = marketUserExample.createCriteria();
        if(!StringUtils.isEmpty(username)){
            criteria.andUsernameLike("%"+username+"%");
        }
        if(!StringUtils.isEmpty(mobile)){
            criteria.andMobileLike("%"+mobile+"%");
        }
        page="1";
        limit="1";
        marketUserExample.setOrderByClause(sort+" "+order);
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<MarketUser> marketUsers = userMapper.selectByExample(marketUserExample);
        session.commit();
        session.close();
        return marketUsers;
    }
}
